package com.example.emailcraft.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.emailcraft.entity.Users;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UsersMapper extends BaseMapper<Users> {

    /**
     * 根据用户名查询用户
     * @param username 用户名
     * @return 用户信息（Optional包装）
     */
    @Select("SELECT * FROM users WHERE username = #{username}")
    Users findByUsername(@Param("username") String username);

    @Select("SELECT r.role_code FROM roles r " +
            "JOIN user_roles ur ON r.id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    List<String> getUserRoles(Long userId);
    @Select("SELECT username FROM users WHERE email = #{email}")
    String findByEmail(@Param("email") String email);
}
